
/**
 * @file alsophila.h
 * libalsophila public header for function declarations
 */

#ifndef ALSOPHILA_H
#define ALSOPHILA_H

#ifdef __cplusplus
extern "C" {
#endif

#include "alsophila-types.h"

/**
 * @defgroup encoding Main encoding functions
 * @{
 */

/**
 * Gets the libalsophila version string.
 */
const char *alsophila_get_version(void);

/**
 * Sets the parameters for an encoding context to their default values.
 * @param s The encoding context
 */
void alsophila_set_defaults(AlsophilaContext *s);

/**
 * Initializes an encoding context.
 * This must be called before any calls to @c alsophila_encode_frame
 * @param s The encoding context
 * @return Returns 0 on success, non-zero on failure.
 */
int alsophila_encode_init(AlsophilaContext *s);

/**
 * Encodes a single AC-3 frame.
 * @param s    The encoding context
 * @param[out] frame        Pointer to output frame
 * @param[in]  samples      Pointer to input audio samples
 * @param[in]  count        Number of input audio samples (per channel);
 * must be equal to A52_SAMPLES_PER_FRAME, less than A52_SAMPLES_PER_FRAME
 * for the last frame, and equal to 0 while flushing
 * @return Returns the number of bytes written to @p frame_buffer, or returns
 * a negative value on error.
 */
int alsophila_encode_frame(AlsophilaContext *s, AlsophilaFrame *frame,
                           const void *samples, int count);

/**
 * Sets the parameters in the context @p s to their default values.
 * @param s The encoding context
 */
void alsophila_encode_close(AlsophilaContext *s);

/** @} end encoding functions */

/**
 * @defgroup utility Utility functions
 * @{
 */

/**
 * Determines the proper A/52 acmod and lfe parameters based on the
 * number of channels and the WAVE_FORMAT_EXTENSIBLE channel mask.  If the
 * chmask value has the high bit set to 1 (e.g. 0xFFFFFFFF), then the default
 * plain WAVE channel selection is assumed.
 * @param[in]  ch      number of channels
 * @param[in]  chmask  channel mask
 * @param[out] acmod   pointer to audio coding mode
 * @param[out] lfe     pointer to LFE flag
 * @return On error, the @p acmod and @p lfe output params are set to -1 and
 * the function returns -1;  on success, the @p acmod and @p lfe params are set
 * to appropriate values and the function returns 0.
 */
int alsophila_wav_channels_to_acmod(int ch, unsigned int chmask, int *acmod,
                                    int *lfe);

/**
 * Takes a channel-interleaved array of audio samples, where the channel order
 * is the default WAV order. The samples are rearranged to the proper A/52
 * channel order based on the @p acmod and @p lfe parameters.
 * @param     samples  array of interleaved audio samples
 * @param[in] n        number of samples in the array
 * @param[in] ch       number of channels
 * @param[in] fmt      sample format
 * @param[in] acmod    audio coding mode
 */
void alsophila_remap_wav_to_a52(void *samples, int n, int ch,
                                A52SampleFormat fmt, int acmod);

/**
 * Takes a channel-interleaved array of audio samples, where the channels are
 * in MPEG order. The samples are rearranged to the proper A/52 channel order
 * based on the @p acmod parameter.
 * @param     samples  array of interleaved audio samples
 * @param[in] n        number of samples in the array
 * @param[in] ch       number of channels
 * @param[in] fmt      sample format
 * @param[in] acmod    audio coding mode
 */
void alsophila_remap_mpeg_to_a52(void *samples, int n, int ch,
                                 A52SampleFormat fmt, int acmod);

/** @} end utility functions */

#if defined(__cplusplus)
}
#endif

#endif /* ALSOPHILA_H */
